#!/usr/bin/env bash

killTomcat() {
  pid=`lsof -i:9090|awk 'END{print $2}'`
  echo "pid: $pid"
  if [ "$pid" = "" ]
  then
    echo "no pid alive"
  else
    kill -9 $pid
  fi
}

cd $PROJECT_PATH/disk

mvn clean install

killTomcat

rm -rf $TOMCAT_APP_PATH/webapps/ROOT
rm -f $TOMCAT_APP_PATH/webapps/ROOT.jar
rm -f $TOMCAT_APP_PATH/webapps/disk-0.0.1-SNAPSHOT.jar

cp $PROJECT_PATH/disk/target/disk-0.0.1-SNAPSHOT.jar $TOMCAT_APP_PATH/webapps/

cd $TOMCAT_APP_PATH/webapps/

mv disk-0.0.1-SNAPSHOT.jar ROOT.jar

java -jar ROOT.jar &